﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Data;

#if !SILVERLIGHT
namespace UIT.WPF.Renderers.Specials
#else
namespace UIT.Silverlight.Renderers.Specials
#endif
{
    public class KeyBindingRenderer
    {
        public KeyBindingRenderer(UIElement result)
        {
            Result = result;
        }

        public void Render(Controls.IControl control)
        {
#if !SILVERLIGHT
            foreach (UIT.Events.Keyboard.KeyCommandBinding commandKeyBinding in control.KeyCommandBindings)
            {
                KeyBinding keyBinding = new KeyBinding(new Command(commandKeyBinding.CommandName), Converters.KeyConverter.Convert(commandKeyBinding.Key & Events.Keyboard.Keys.KeyCode), Converters.KeyConverter.Convert(commandKeyBinding.Modifiers));
                BindingOperations.SetBinding(keyBinding, InputBinding.CommandParameterProperty, new Binding("CommandParameter") { Source = commandKeyBinding });
                Result.InputBindings.Add(keyBinding);
            }
#endif
        }

        public UIElement Result { get; set; }
    }
}
